//
//  NextStepViewController.m
//  QXShowing
//
//  Created by 王道道 on 2018/5/1.
//  Copyright © 2018年 doll_dream. All rights reserved.
//

#define foot_Height 120 *SizeScale

#import "NextStepViewController.h"

#import "BHSingleButton.h"
#import "LastStepViewController.h"

static NSString *const listCell = @"listCell";

@interface NextStepViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
//@property (nonatomic, strong) NSArray *dataArray;

@property (nonatomic, strong) NSString *nextTitle;
@property (nonatomic, strong) NSString *chooseItem;

@property (nonatomic, strong) NSIndexPath *chooseIndex;

@property (nonatomic, strong) BHSingleButton *nextBtn;

@end

@implementation NextStepViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initNavBarBackBtn];
    self.view.backgroundColor = Bg_Color_F7F7F7;
    
//    [self setUpData];
    [self setUpUI];
}

/*
 - (void)setUpData {
 if (self.page == 1) {
 //地区
 self.title = @"地区选择";
 self.dataArray = [[NSMutableArray alloc] initWithObjects:@"武汉", @"上海", @"杭州", nil];
 }
 else if (self.page == 2) {
 //展馆
 self.title = @"展馆选择";
 [self requestPostBH_Exhibition_getExhibitionHallByCityId:YES PageCount:1];
 }
 else if (self.page == 3) {
 //展会
 self.title = @"展会选择";
 [self requestPostBH_Exhibition_getExhibitionByHallId:YES PageCount:1];
 }
 else if (self.page == 4) {
 //展区
 self.title = @"展区选择";
 [self requestPostBH_Exhibition_getExhibitionLayout:YES PageCount:1];
 }
 else {
 //展位号
 }
 }
 */

- (void)setUpUI {
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, App_Frame_Width, App_Frame_Height-kNavbarAndStatusBar-foot_Height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableHeaderView = [[UIView alloc]init];
    _tableView.tableFooterView = [[UIView alloc]init];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _tableView.scrollsToTop = NO;
    _tableView.backgroundColor = Bg_Color_F7F7F7;
    [self.view addSubview:_tableView];
    
    _nextBtn = [[BHSingleButton alloc] initWithFrame:CGRectMake(10, App_Frame_Height-kNavbarAndStatusBar-foot_Height, App_Frame_Width-(10*2), 60)];
    NSString *btnName = [NSString stringWithFormat:@"下一步（%ld/5）", (long)self.page];
    _nextBtn.button_name(btnName);
    [_nextBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_nextBtn];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.tableView.frame = CGRectMake(0, 0, App_Frame_Width, CGRectGetHeight(self.view.bounds));
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:listCell];
    }
    cell.textLabel.text = self.dataArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (self.chooseIndex == indexPath) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.chooseIndex = indexPath;
    [self.tableView reloadData];
    self.chooseItem = self.dataArray[indexPath.row];
}

- (void)nextAction {
    /*
     if([BHSettingUtil dataAndStringIsNull:self.chooseIndex]) {
     [[BHAlertUtil alertManager] showPromptInfo:@"请先选择"];
     }
     else {
     [self.chooseArray replaceObjectAtIndex:self.page-1 withObject:self.chooseItem];
     if (self.page == 1) {
     //地区-----跳转展馆
     [self requestPostBH_Region_getRegionId:self.chooseArray[0]];
     }
     else if (self.page == 2) {
     //展馆-----跳转展会
     NextStepViewController *next = [[NextStepViewController alloc] init];
     next.title = self.nextTitle;
     next.page = 3;
     next.chooseArray = self.chooseArray;
     [self pushViewController:next animated:YES];
     }
     else if (self.page == 3) {
     //展会-----跳转展区
     NextStepViewController *next = [[NextStepViewController alloc] init];
     next.title = self.nextTitle;
     next.page = 4;
     next.chooseArray = self.chooseArray;
     [self pushViewController:next animated:YES];
     }
     else if (self.page == 4) {
     //展区-----跳转展位号
     LastStepViewController *next = [[LastStepViewController alloc] init];
     next.chooseArray = self.chooseArray;
     [self pushViewController:next animated:YES];
     }
     else {
     }
     }
     */
     }


    /*
     #pragma mark - 接口
     //- (void)_loadData:(id)response Refresh:(BOOL)refresh {
     //    if (refresh) [self.dataArray removeAllObjects];
     //    NSArray *arr = [NSArray yy_modelArrayWithClass:[MyShowListModel class] json:response];
     //    [self.dataArray addObjectsFromArray:arr];
     //    if (arr.count < 10) {
     //        [self.tableView endRefreshingWithNoMoreData];
     //    }
     //    [self.tableView reloadData];
     //}
     
     //地区id
     //- (void)requestPostBH_RegiongetAllCityes:(BOOL)refresh PageCount:(NSInteger)pageCount {
     //    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     //    if (refresh) [self.dataArray removeAllObjects];
     //    NSMutableDictionary *params = [NSMutableDictionary dictionary];
     //    //    [params setObject:@"杭州" forKey:@"region_name"];//383杭州
     //    [PPHTTPRequest requestPostBH_RegiongetAllCityes:^(id response, BOOL success) {
     //        if (self.dataArray.count == 0 && [response isKindOfClass:[NSString class]]) {
     //            //            self.tableView.placeholderShow(YES).isButtonHidden(YES).prompt_title(@"您还没有好友去添加吧！").prompt_image(@"icon_no_friend");
     //        }
     //        //        else self.tableView.placeholderShow(NO);
     //        if (success && ![response isKindOfClass:[NSString class]]) {
     //            [self _loadData:response Refresh:refresh];
     //        }
     //        [self.tableView reloadData];
     //        [MBProgressHUD hideHUDForView:self.view animated:YES];
     //    } params:params];
     //}
     
     - (void)requestPostBH_Region_getRegionId:(NSString *)cityName {
     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
     [params setObject:cityName forKey:@"region_name"];//383杭州
     [PPHTTPRequest requestPostBH_Region_getRegionId:^(id response, BOOL success) {
     if (success) {
     [self.chooseArray replaceObjectAtIndex:0 withObject:response];
     
     NextStepViewController *next = [[NextStepViewController alloc] init];
     next.title = self.nextTitle;
     next.page = 2;
     next.chooseArray = self.chooseArray;
     [self pushViewController:next animated:YES];
     }
     [MBProgressHUD hideHUDForView:self.view animated:YES];
     } params:params];
     }
     
     //展馆
     - (void)requestPostBH_Exhibition_getExhibitionHallByCityId:(BOOL)refresh PageCount:(NSInteger)pageCount {
     if (refresh) [[BHAlertUtil alertManager]showLoading:@""];
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
     [params setObject:@"" forKey:@"vague"];
     //    [params setObject:@"383" forKey:@"city_id"];
     [params setObject:self.city_id forKey:@"city_id"];
     [params setObject:[NSString stringWithFormat:@"%ld",pageCount] forKey:@"page"];
     [params setObject:@"10" forKey:@"pagesize"];
     
     [PPHTTPRequest requestPostBH_Exhibition_getExhibitionHallByCityId:^(id response, BOOL success) {
     if (self.dataArray.count == 0 && [response isKindOfClass:[NSString class]]) {
     //            self.collectionView.placeholderShow(YES).prompt_title((NSString *)response).isButtonHidden(YES);
     }else self.tableView.placeholderShow(NO);
     if (success && ![response isKindOfClass:[NSString class]]) {
     [self _loadData:response Refresh:refresh];
     }
     [[BHAlertUtil alertManager]hiddenLoading];
     } params:params];
     }
     
     //展会
     - (void)requestPostBH_Exhibition_getExhibitionByHallId:(BOOL)refresh PageCount:(NSInteger)pageCount {
     self.dataArray.count != 0 ?: [[BHAlertUtil alertManager]showLoadingView:self.view];
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
     [params setObject:@"" forKey:@"vague"];
     [params setObject:self.hall_id forKey:@"hall_id"];
     [params setObject:[NSString stringWithFormat:@"%ld",(long)pageCount] forKey:@"page"];
     [params setObject:@"10" forKey:@"pagesize"];
     
     [PPHTTPRequest requestPostBH_Exhibition_getExhibitionByHallId:^(id response, BOOL success) {
     if (self.dataArray.count == 0 && [response isKindOfClass:[NSString class]]) {
     //            self.collectionView.placeholderShow(YES).prompt_title((NSString *)response).isButtonHidden(YES);
     }else self.tableView.placeholderShow(NO);
     if (success && ![response isKindOfClass:[NSString class]]) {
     [self _loadData:response Refresh:refresh];
     }
     [[BHAlertUtil alertManager]hiddenLoading];
     } params:params];
     }
     
     //展区
     - (void)requestPostBH_Exhibition_getExhibitionLayout:(BOOL)refresh PageCount:(NSInteger)pageCount {
     self.dataArray.count != 0 ?: [[BHAlertUtil alertManager]showLoadingView:self.view];
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
     [params setObject:self.Id forKey:@"id"];
     
     [PPHTTPRequest requestPostBH_Exhibition_getExhibitionLayout:^(id response, BOOL success) {
     if (self.dataArray.count == 0 && [response isKindOfClass:[NSString class]]) {
     //            self.collectionView.placeholderShow(YES).prompt_title((NSString *)response).isButtonHidden(YES);
     }else self.tableView.placeholderShow(NO);
     if (success && ![response isKindOfClass:[NSString class]]) {
     [self _loadData:response Refresh:refresh];
     }
     [[BHAlertUtil alertManager]hiddenLoading];
     } params:params];
     }
     */

@end
